package com.sentrix.auto.printercenter.infrastructure.persistence.impl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.sentrix.auto.printercenter.domain.entity.PrinterTaskEntity;
import com.sentrix.auto.printercenter.domain.entity.StationEntity;
import com.sentrix.auto.printercenter.infrastructure.persistence.IStationRepository;
import com.sentrix.auto.printercenter.infrastructure.persistence.dao.mapper.StationMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class StationRepositoryImpl extends ServiceImpl<StationMapper, StationEntity> implements IStationRepository {
    @Override
    public StationEntity findByCode(String stationCode) {
        return this.getOne(query().eq(StationEntity::getCode, stationCode));
    }

    @Override
    public void removeByCode(String stationCode) {
        this.remove(query().eq(StationEntity::getCode, stationCode));
    }

    @Override
    public Page<StationEntity> pageQuery(int currentPage, int pageSize, String code, String name, String printerCodes) {
        return this.page(Page.of(currentPage, pageSize), query()
                .eq(StationEntity::getCode, code, StringUtils::isNotBlank)
                .eq(StationEntity::getName, name, StringUtils::isNotBlank)
                .like(StationEntity::getPrinterCodes, printerCodes, StringUtils::isNotBlank)
        );
    }
}
